// pages/flag_member2/flag_member2.js
var common = require("../../common/common.js").common;

const app = getApp();

Page({
    /**
   * 页面的初始数据
   */
    data: {
        alert: 0,
        member: "",
        search_con: ""
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.setData({
            domain: app.globalData.domain.slice(0, -10)
        });
        var that = this;
        that.getData();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {},
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    alert: function() {
        var alert = this.data.alert;
        if (alert == 0) {
            alert = 1;
        } else {
            alert = 0;
        }
        this.setData({
            alert: alert
        });
    },
    getData: function() {
        var openid = wx.getStorageSync("user").openid;
        var that = this;
        common.request({
            endpoint: "Leader/undermember/underchildren",
            method: "post",
            data: {
                openid: openid,
                search: ""
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                console.log(res);
                that.setData({
                    member: res.extra
                });
            },
            fail: res => {
                console.log("失败" + res);
            }
        });
    },
    getValue: function(e) {
        var that = this;
        that.setData({
            search_con: e.detail.value
        });
    },
    search: function(e) {
        var openid = wx.getStorageSync("user").openid;
        var that = this;
        var search = that.data.search_con;
        console.log(search);
        common.request({
            endpoint: "Leader/undermember/underchildren",
            method: "post",
            data: {
                openid: openid,
                search: search
            },
            header: {
                "content-type": "application/json"
            },
            success: res => {
                console.log(res);
                that.setData({
                    member: res.extra
                });
            }
        });
    },
    alert: function() {
        var alert = this.data.alert;
        if (alert == 0) {
            alert = 1;
        } else {
            alert = 0;
        }
        this.setData({
            alert: alert
        });
    },
    //跳转共用生成海报页面
    makeposter: function() {
        wx.navigateTo({
            url: "/pages/share/share?types=group"
        });
    }
});